
export default {
  watch: {
    '$i18n.locale': function (val, old) {
      this.i18nTable();
    },
  },
  mounted() {
    this.i18nTable();
  },

  methods: {

    i18nTable() {
      this.parseColumn();
      this.parseButton();
      this.parseOption();
    },

    // 列名
    parseColumn() {
      if (this.mainTable.columns) {
        this.mainTable.columns.forEach(col => {
          if (col.hasOwnProperty('t')) {
            col.title = this.$t(col.t);
          }
          if (col.children) {
            col.children.forEach(item => {
              if (item.hasOwnProperty('t')) {
                item.title = this.$t(item.t);
              }
            })
          }
        });
      }


      try {
        if (this.mainTable.rowHandle && this.mainTable.rowHandle.hasOwnProperty('t')) {
          this.mainTable.rowHandle.columnHeader = this.$t(this.mainTable.rowHandle.t);
        }
      } catch (error) {

      }
    },

    // 操作列按钮
    parseButton() {
      if (this.mainTable.rowHandle && this.mainTable.rowHandle.custom) {
        this.mainTable.rowHandle.custom.forEach(btn => {
          if (btn.hasOwnProperty('t')) {
            btn.text = this.$t(btn.t);
          }
        });
      }
    },

    // 表格选项
    parseOption() {
      if (this.mainTable.options.hasOwnProperty('t')) {
        this.mainTable.options.emptyText = this.$t(this.mainTable.options.t);
      }
    },


  },

}